package vip.xiaonuo.smzq.modular.lifecycle.controller.entity;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

import java.util.stream.Collectors;
import java.util.Date;

import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.smzq.modular.drkqs.mapper.KclZyclMapper;
import vip.xiaonuo.smzq.modular.lifecycle.constant.WebResultStatusConstant;
import vip.xiaonuo.smzq.modular.lifecycle.entity.KclZycl;
import vip.xiaonuo.smzq.modular.lifecycle.result.ResultWrapper;
import vip.xiaonuo.smzq.modular.lifecycle.result.WebResult;
import vip.xiaonuo.smzq.modular.lifecycle.service.entity.KclZyclService;

/**
 * <p>
 * 资源储量 前端控制器
 * </p>
 *
 * @author 于彦飞
 * @since 2024-03-25
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@Api(tags = {"资源储量模块"})
@RestController(value = "lifeCycleKclZyclController")
@RequestMapping("/kclZycl" )

public class KclZyclController {
    @Autowired
    private KclZyclService kclZyclService;
    @Autowired
    private KclZyclMapper kclZyclMapper;
    @Resource
    ResultWrapper resultWrapper;

    @ApiOperation(value = "查询所有资源储量接口", notes = "查询所有资源储量接口")
    @PostMapping(value = "/list")
    public WebResult queryKclZyclList(@RequestBody KclZycl kclZycl) {

        return resultWrapper.getSuccessWebResult(kclZyclService.queryKclZyclList(kclZycl));
    }

    @ApiOperation(value = "分页查询资源储量接口", notes = "分页查询资源储量接口")
    @PostMapping(value = "/list/page")
    public WebResult queryKclZyclListPage(@RequestBody KclZycl kclZycl) {

        return resultWrapper.getSuccessWebResult(kclZyclService.queryKclZyclListPage(kclZycl));
    }



    @ApiOperation(value = "根据id查询资源储量接口", notes = "根据id查询资源储量接口")
    @GetMapping(value = "byId/{id}")
    public WebResult queryKclZyclById(@PathVariable("id") String id) {

        KclZycl entity  = kclZyclService.getById(id);
//        DictConvertUtil.convertToDictionary(entity,null);

        return resultWrapper.getSuccessWebResult(entity);
    }

    @ApiOperation(value = "根据id删除资源储量接口", notes = "根据id删除资源储量接口")
    @PostMapping(value = "d/{id}")
    public WebResult delById(@PathVariable("id")String id) {
        return resultWrapper.getWebResultByDelSuccess(kclZyclService.delKclZycl(id));
    }

    @ApiOperation(value = "根据id批量删除资源储量接口", notes = "根据id批量删除资源储量接口")
    @PostMapping(value = "/d/batch")
    public WebResult delById(@RequestBody List<String> ids) {
        return resultWrapper.getWebResultByDelSuccess(kclZyclService.delKclZyclBatch(ids));
    }

    @ApiOperation(value = "新增资源储量接口", notes = "新增资源储量接口")
    @PostMapping(value = "/save")
    public WebResult save(@RequestBody KclZycl kclZycl) {
        boolean isSuccess = kclZyclService.save(kclZycl);
        if(isSuccess){
            return resultWrapper.getWebResultByWebResultStatusConstant(WebResultStatusConstant.SUCCESS_OPERATION, kclZycl.getPkid());
        }
        return resultWrapper.getWebResultByWebResultStatusConstant(WebResultStatusConstant.PROCESS_CREATE, null);
    }

    @ApiOperation(value = "批量新增资源储量接口", notes = "批量资源储量接口")
    @PostMapping(value = "save/batch")
    public WebResult saveBath(@RequestBody List<KclZycl> kclZycls) {
        boolean isSuccess = kclZyclService.saveBatch(kclZycls);
        if(isSuccess){
            List<String> ids = kclZycls.stream().map(ele->ele.getPkid()).collect(Collectors.toList());
            return resultWrapper.getWebResultByWebResultStatusConstant(WebResultStatusConstant.SUCCESS_OPERATION, ids);
        }
        return resultWrapper.getWebResultByWebResultStatusConstant(WebResultStatusConstant.PROCESS_CREATE, null);
    }

    @ApiOperation(value = "更新用户接口", notes = "id必须有值")
    @PostMapping(value = "/update")
    public WebResult update(@RequestBody KclZycl kclZycl) {
        return resultWrapper.getWebResultByEditSuccess(kclZyclService.updateById(kclZycl));
    }
    @ApiOperation(value = "批量更新资源储量接口", notes = "id必须有值")
    @PostMapping(value = "/update/batch")
    public WebResult updateBatch(@RequestBody List<KclZycl> kclZycls) {
        return resultWrapper.getWebResultByCreateSuccess(kclZyclService.updateBatchById(kclZycls));
    }
    @ApiOperation(value = "新增或者更新接口", notes = "id无值为新增反之则为更新")
    @PostMapping(value = "/saveOrUpdate")
    public WebResult saveOrUpdate(@RequestBody KclZycl kclZycl) {

        return resultWrapper.getSuccessWebResult(kclZyclService.saveOrUpdate(kclZycl));
    }
    @ApiOperation(value = "批量新增或者更新接口", notes = "id无值为新增反之则为更新")
    @PostMapping(value = "/saveOrUpdate/batch")
    public WebResult saveOrUpdate(@RequestBody List<KclZycl> kclZycls) {

        return resultWrapper.getSuccessWebResult(kclZyclService.saveOrUpdateBatch(kclZycls));
    }

}
